package com.zillion.web.controller.health;

import com.zillion.common.annotation.Log;
import com.zillion.common.core.controller.BaseController;
import com.zillion.common.core.domain.AjaxResult;
import com.zillion.common.core.page.TableDataInfo;
import com.zillion.common.enums.BusinessType;
import com.zillion.common.utils.poi.ExcelUtil;
import com.zillion.health.domain.HealthEmployeeReserve;
import com.zillion.health.domain.SelfCostReserve;
import com.zillion.health.service.IHealthEmployeeReserveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 从业人员预约Controller
 *
 * @author zillion
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/health/reserve")
public class HealthEmployeeReserveController extends BaseController {
    @Autowired
    private IHealthEmployeeReserveService healthEmployeeReserveService;

    /**
     * 查询从业人员预约列表
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthEmployeeReserve healthEmployeeReserve) {
        startPage();
        List<HealthEmployeeReserve> list = healthEmployeeReserveService.selectHealthEmployeeReserveList(healthEmployeeReserve);
        return getDataTable(list);
    }

    /**
     * 下载健康证
     *
     * @param id 下载人员数据id
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:downloadCard')")
    @PostMapping("/downloadCard")
    public AjaxResult downloadCard(@RequestParam String id) {
        return AjaxResult.success(healthEmployeeReserveService.downloadCard(id));
    }


    /**
     * 导出从业人员预约列表
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:export')")
    @Log(title = "从业人员预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthEmployeeReserve healthEmployeeReserve) {
        List<HealthEmployeeReserve> list = healthEmployeeReserveService.selectHealthEmployeeReserveList(healthEmployeeReserve);
        ExcelUtil<HealthEmployeeReserve> util = new ExcelUtil<HealthEmployeeReserve>(HealthEmployeeReserve.class);
        util.exportExcel(response, list, "从业人员预约数据");
    }

    /**
     * 获取从业人员预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(healthEmployeeReserveService.selectHealthEmployeeReserveById(id));
    }

    /**
     * 新增从业人员预约
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:add')")
    @Log(title = "从业人员预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthEmployeeReserve healthEmployeeReserve) {
        return toAjax(healthEmployeeReserveService.insertHealthEmployeeReserve(healthEmployeeReserve));
    }

    /**
     * 新增从业人员自费预约
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:add')")
    @Log(title = "从业人员预约", businessType = BusinessType.INSERT)
    @PostMapping("/addSelfCostReserve")
    public AjaxResult addSelfCostReserve(@RequestBody SelfCostReserve selfCostReserve) {
        return toAjax(healthEmployeeReserveService.insertHealthSelfCostReserve(selfCostReserve));
    }

    /**
     * 修改从业人员预约
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:edit')")
    @Log(title = "从业人员预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthEmployeeReserve healthEmployeeReserve) {
        return toAjax(healthEmployeeReserveService.updateHealthEmployeeReserve(healthEmployeeReserve));
    }

    /**
     * 删除从业人员预约
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:remove')")
    @Log(title = "从业人员预约", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(healthEmployeeReserveService.deleteHealthEmployeeReserveByIds(ids));
    }

    /**
     * 处理从业人员发证状态--处理提交证件数据到省平台业务
     */
    @PreAuthorize("@ss.hasPermi('health:reserve:sendCard')")
    @Log(title = "从业人员预约", businessType = BusinessType.UPDATE)
    @PutMapping("/{ids}")
    public AjaxResult updateIsSendCard(@PathVariable Long[] ids) {
        return success(healthEmployeeReserveService.updateIsSendCard(ids));
    }
}
